package com.ampaiva.dao;

import java.io.IOException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.ingeniouscamel.droid.dbutil.SQLiteDBDeploy;

public class MyDroidSQLiteOpenHelper extends SQLiteOpenHelper {
    private final Context context;
    private final String zipFile;
    private static final int __DB_VERSION = 1;

    public MyDroidSQLiteOpenHelper(Context context, String zipFile, String dbName) {
        super(context, dbName, null, __DB_VERSION);
        this.context = context;
        this.zipFile = zipFile;
    }

    @Override
    public void onCreate(SQLiteDatabase sqlLiteDb) {
        try {
            SQLiteDBDeploy.deploy(sqlLiteDb, this.context, zipFile);

            // if you like to download file from remote site comment above line
            // and uncomment below line.
            // SQLiteDBDeploy.deploy(sqlLiteDb,"http://ingenious-camel.googlecode.com/svn/trunk/SQLiteDBDeployer/assets/northwind.zip");
        } catch (IOException e) {
            Log.e(MyDroidSQLiteOpenHelper.class.getSimpleName(), e.getMessage(), e);
            throw new Error(e.getMessage());
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqlLiteDb, int oldVersion, int newVersion) {

    }
}
